package cn.cena.pay.service.impl;

import cn.cena.basic.service.impl.BaseServiceImpl;
import cn.cena.basic.util.LoginContextUtil;
import cn.cena.pay.domain.PayBill;
import cn.cena.pay.service.IPayBillService;
import cn.cena.user.domain.Logininfo;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

@Service
public class PayBillServiceImpl extends BaseServiceImpl<PayBill> implements IPayBillService {

    @Override
    public void save(String digest, BigDecimal money,
                     String unionPaySn, Integer businessType,Integer payChannel, Long businessKey,
                     String shopName, Long shopId) {
        PayBill payBill = new PayBill();
        payBill.setDigest(digest);
        payBill.setMoney(money);
        // 待支付
        payBill.setState(PayBill.PAY_WAIT);
        payBill.setPayChannel(payChannel);
        payBill.setCreateTime(new Date());
        payBill.setUnionPaySn(unionPaySn);
        payBill.setBusinessType(businessType);
        payBill.setBusinessKey(businessKey);

        Logininfo logininfo = LoginContextUtil.getLoginContext();
        payBill.setUser_id(logininfo.getId());
        payBill.setNickName(logininfo.getUsername());
        payBill.setShopName(shopName);
        payBill.setShop_id(shopId);

        super.add(payBill);
    }

}
